package de.hb.bv1.u07;

import ij.ImagePlus;
import ij.plugin.filter.PlugInFilter;
import ij.process.ImageProcessor;

/**
 * Example of how to separate logic and gui
 * All Plugins have to implement the PlugInFilter
 * 
 * @author gruppe13
 * @version 2012-01-22
 *
 */
public class Gruppe13_U07_Plugins implements PlugInFilter {

	/**
	 * Used to identify which filter to run
	 * @author gruppe13
	 * @see plugins.config
	 */
	private enum PluginFunctions {
		NONE, HOUGH
	};
	private PluginFunctions func = PluginFunctions.NONE;

	/**
	 * Method which is called when the filter is loaded
	 * 
	 * @param arg the argument given in plugins.config
	 * @param imp the currently active image
	 */
	@Override
	public int setup(String arg, ImagePlus imp) {
		for (PluginFunctions inv : PluginFunctions.values()) {
			if (inv.name().equals(arg)) {
				func = inv;
				break;
			}
		}
		//we can handle 8-bit grayscale images
		return DOES_8G+DOES_RGB;
	}

	/** 
	 * Called once to process the image
	 */
	@Override
	public void run(ImageProcessor ip) {
		long startTime = System.nanoTime();
		switch (func) {
		case HOUGH:
			// (!)
			Gruppe13_U07_Logic.hough(ip);
			break;
	 
		}
		System.out.print(String.format("%s processing time: %.4fs\n", func.name(),
				(System.nanoTime() - startTime) * 1e-9));
	}

}